<?php
class StringHelper
{
	/**
	 * 支持从半路截取中文字符串
	 */
	static function strcut($string, $sublen, $start = 0)
	{
		$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
		preg_match_all($pa, $string, $t_string);
		//if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
		return join('', array_slice($t_string[0], $start, $sublen));
	}
	
	/**
	 * 转换字符串为utf-8编码
	 */
	static function encode($cont)
	{
		$encode	=	mb_detect_encoding($cont, 'GBK, UTF-8');
		($encode=='CP936') ? $encode='GBK' : null;
		if($encode!='UTF-8')
		{
			return iconv($encode, 'UTF-8', $cont);
		}
		return $cont;
	}
	
}
?>